package com.huxin.servelt;

import com.huxin.service.Userservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/returnBook")
public class ReturnBookServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求方法
        request.setCharacterEncoding("utf-8");
        //处理响应乱码
        response.setContentType("text/json;charset=utf-8");
        String id=request.getParameter("bid");
        // todo
        Integer userId = (Integer) request.getSession().getAttribute("userId");
        //调用service
        Userservice service = new Userservice();
        int i=service.updateservice(id);
        int j=service.updateBook(id);
        if(j>0&&i>0){
            service.addUserMaxNum(userId);
            response.getWriter().write("true");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
